package com.study.rocket.order;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @author mjy
 * @date 2021/12/10
 * @description
 */
public class Consumer {


    public static void main(String[] args) throws Exception {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("group2");
        consumer.setNamesrvAddr("192.168.15.170:9876");
        consumer.subscribe("orderTopic","order");
        consumer.registerMessageListener(new MessageListenerOrderly() {
            @Override
            public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext consumeOrderlyContext) {
                for (MessageExt msg : msgs) {
                    System.out.println("====================");
                    System.out.println("当前线程名称:【"+Thread.currentThread().getName()+"】");
                    System.out.println("消费消息"+new String(msg.getBody()));
                    System.out.println();
                }
                return ConsumeOrderlyStatus.SUCCESS;
            }
        });
        consumer.start();

    }

}
